@using Microsoft.AspNetCore.Components;
@inject NavigationManager navigationManager

    <MatNavMenu Multi="true" Class="app-sidebar">
        <MatNavItem Href="@navigationManager.ToAbsoluteUri(" ").AbsoluteUri" NavLinkMatch="NavLinkMatch.All">
            <MatIcon>home</MatIcon> <span class="miniHover">Home page</span>
        </MatNavItem>

        <MatNavItem Href="@navigationManager.ToAbsoluteUri("todo_list").AbsoluteUri">
            <MatIcon>list_alt</MatIcon> <span class="miniHover">Todo List</span>
        </MatNavItem>

        <MatNavSubMenu>
            <MatNavSubMenuHeader>
                <MatNavItem AllowSelection="false">
                    <MatIcon>stars</MatIcon><span class="miniHover"> Features</span>
                </MatNavItem>
            </MatNavSubMenuHeader>
            <MatNavSubMenuList>
                <MatNavItem Href="@navigationManager.ToAbsoluteUri("drag_and_drop").AbsoluteUri">
                    <MatIcon>touch_app</MatIcon> <span class="miniHover">Drag and Drop</span>
                </MatNavItem>
                <MatNavItem Href="@navigationManager.ToAbsoluteUri("screenshots").AbsoluteUri">
                    <MatIcon>screen_share</MatIcon> <span class="miniHover">Screenshots</span>
                </MatNavItem>
            </MatNavSubMenuList>
        </MatNavSubMenu>

        <MatNavItem Href="@navigationManager.ToAbsoluteUri("dashboard").AbsoluteUri" Disabled="@(!IsLoggedIn)">
            <MatIcon>bar_chart</MatIcon> <span class="miniHover">Dashboard</span>
        </MatNavItem>

        <MatNavSubMenu>
            <MatNavSubMenuHeader>
                <MatNavItem AllowSelection="false" Disabled="@(!IsLoggedIn)">
                    <MatIcon>mail_outline</MatIcon>
                    <span class="miniHover"> Email</span>
                </MatNavItem>
            </MatNavSubMenuHeader>
            <MatNavSubMenuList>
                <MatNavItem Href="@navigationManager.ToAbsoluteUri("email_view").AbsoluteUri" Disabled="@(!IsLoggedIn)">
                    <MatIcon>inbox</MatIcon> <span class="miniHover">Read Email</span>
                </MatNavItem>
                <MatNavItem Href="@navigationManager.ToAbsoluteUri("email").AbsoluteUri" Disabled="@(!IsLoggedIn)">
                    <MatIcon>send</MatIcon> <span class="miniHover">Send Email</span>
                </MatNavItem>
            </MatNavSubMenuList>
        </MatNavSubMenu>

        <AuthorizeView Policy="@Policies.IsAdmin" Context="AuthorizeContext">
            <Authorized>
                <MatNavSubMenu>
                    <MatNavSubMenuHeader>
                        <MatNavItem AllowSelection="false">
                            <MatIcon>settings_applications</MatIcon> <span class="miniHover">Admin</span>
                        </MatNavItem>
                    </MatNavSubMenuHeader>
                    <MatNavSubMenuList>
                        <MatNavItem Href="@navigationManager.ToAbsoluteUri("admin/users").AbsoluteUri">
                            <MatIcon>supervisor_account</MatIcon> <span class="miniHover">Users</span>
                        </MatNavItem>
                        <MatNavItem Href="@navigationManager.ToAbsoluteUri("admin/roles").AbsoluteUri">
                            <MatIcon>supervisor_account</MatIcon> <span class="miniHover">Roles</span>
                        </MatNavItem>
                        <MatNavItem Href="@navigationManager.ToAbsoluteUri("admin/blazor_middlware_audit").AbsoluteUri">
                            <MatIcon>change_history</MatIcon> <span class="miniHover">Api Audit Log</span>
                        </MatNavItem>
                        <MatNavItem Href="@navigationManager.ToAbsoluteUri("admin/dBlogViewer").AbsoluteUri">
                            <MatIcon>notes</MatIcon> <span class="miniHover">DB Logging View</span>
                        </MatNavItem>
                    </MatNavSubMenuList>
                </MatNavSubMenu>
            </Authorized>
            <NotAuthorized>
                <MatNavItem Href="@navigationManager.ToAbsoluteUri("admin/users").AbsoluteUri" Disabled="true">
                    <MatIcon>supervisor_account</MatIcon> <span class="miniHover">Admin</span>
                </MatNavItem>
            </NotAuthorized>
        </AuthorizeView>

        <MatNavItem Href="@navigationManager.ToAbsoluteUri("forum").AbsoluteUri" Disabled="@(!IsLoggedIn)">
            <MatIcon>forum</MatIcon> <span class="miniHover">Forum</span>
        </MatNavItem>

        <MatNavItem Href="@navigationManager.ToAbsoluteUri("sponsors").AbsoluteUri">
            <MatIcon>attach_money</MatIcon> <span class="miniHover">Sponsors</span>
        </MatNavItem>
</MatNavMenu>

@code {
    public bool IsLoggedIn = false;

    [CascadingParameter]
    Task<AuthenticationState> authenticationStateTask { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        IsLoggedIn = false;
        var user = (await authenticationStateTask).User;

        if (user.Identity.IsAuthenticated)
        {
            IsLoggedIn = true;
        }

        if (user.IsInRole("Administrator"))
        {
            // Perform some action only available to users in the 'admin' role
            //Console.WriteLine("Administrator");
        }
    }
}
